function addOne(num) {
  console.log('addOne');
  return num + 10;
}

function minusOne(num) {
  console.log('minusOne');
  return num - 1;
}

function addFive(num) {
  console.log('addFive');
  return num + 4;
}

function minusTwo(num) {
  console.log('minusTwo');
  return num - 2;
}

function compose() {
  const args = [].slice.apply(arguments)
  return function (num) {
    console.log('compose')
    return args.reduceRight((res, cb) => cb(res), num)
  }
}
console.log(compose(addOne, minusOne, addFive, minusTwo)(4));